import request from '@/utils/request'
import type { SkuInfoData, SkuInfoDataResponseData, SpuData, SpuHasSaleAttrResponseData, SpuResponseData } from './type'
import type { AllTradeMarkResponseData,SpuImageResponseData } from './type'
import type { BaseSaleAttrResponseData } from './type'
enum API {
    // 获取spu列表
    GET_SPU_LIST_API = '/admin/product/',
    // 获取所有品牌
    GET_SPU_ALL_TRADEMARK_API='/admin/product/baseTrademark/getTrademarkList',
    // 获取该spu图片列表
    GET_SPU_TRADEMARK_IMAGE_API='/admin/product/spuImageList',
    // 获取该spu销售属性列表
    GET_SPU_HAS_SALE_ATTR_API='/admin/product/spuSaleAttrList',
    // 获取所有销售属性用来可能的添加到该spu销售属性列表
    GET_ALL_SALE_ATTR_API='/admin/product/baseSaleAttrList',
    // 添加spu
    ADD_SPU_API='/admin/product/saveSpuInfo',
    // 修改spu
    UPDATE_SPU_API='/admin/product/updateSpuInfo',
    //新增一个SKU
    ADD_SKU_API='/admin/product/saveSkuInfo',
    //查看该spu的sku列表
    GET_SPU_SKU_LIST_API='/admin/product/findBySpuId',
    //删除spu
    DELETE_SPU_API='/admin/product/deleteSpu',
}

export const reqSpuList = (page:number,limit:number,category3Id:number) => request.get<any,SpuResponseData>(API.GET_SPU_LIST_API + `${page}/${limit}?category3Id=${category3Id}`)
export const reqAllTradeMark = () => request.get<any,AllTradeMarkResponseData>(API.GET_SPU_ALL_TRADEMARK_API)
export const reqSpuImageList = (spuId:number) => request.get<any,SpuImageResponseData>(API.GET_SPU_TRADEMARK_IMAGE_API + `/${spuId}`)
export const reqSpuHasSaleAttr = (spuId:number) => request.get<any,SpuHasSaleAttrResponseData>(API.GET_SPU_HAS_SALE_ATTR_API + `/${spuId}`)
export const reqBaseSaleAttr = () => request.get<any,BaseSaleAttrResponseData>(API.GET_ALL_SALE_ATTR_API)
export const reqAddorEditSpu = (data:SpuData) => {
    if(data.id){
        return request.post<any,any>(API.UPDATE_SPU_API,data)
    }
    else{
        return request.post<any,any>(API.ADD_SPU_API,data)
    }
}
export const reqAddSku = (data:SkuInfoData) => request.post<any,any>(API.ADD_SKU_API,data)
export const reqSkuList = (spuId:number) => request.get<any,SkuInfoDataResponseData>(API.GET_SPU_SKU_LIST_API + `/${spuId}`)
export const reqSpuDelete = (spuId:number) => request.delete<any,any>(API.DELETE_SPU_API + `/${spuId}`)